package ar.edu.uba.fi.jmit.monitorengine.backend.server.mock;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import org.apache.log4j.Logger;

import ar.edu.uba.fi.jmit.monitorengine.backend.client.EventService;
import ar.edu.uba.fi.jmit.monitorengine.backend.shared.dto.EventDTO;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class EventServiceMock extends RemoteServiceServlet implements EventService {

	private static final long serialVersionUID = -1159004838797795314L;
	
	public EventServiceMock() {
		super();
		Logger.getLogger(this.getClass()).info("EventServiceMock service created");
	}

	@Override
	public List<EventDTO> getLastRecivedEvents(int from, int to) {
		Logger.getLogger(this.getClass()).info("on MOCK event service");
		EventDTO dto = new EventDTO();
		dto.setId(Long.valueOf(from));
		dto.setEventDate(new Date());
		dto.setPriority("Normal");
		dto.setSource("mock service");
		List<EventDTO> list = new LinkedList<EventDTO>();
		list.add(dto);
		
		dto = new EventDTO();
		dto.setId(Long.valueOf(from + 1));
		dto.setEventDate(new Date());
		dto.setPriority("High Priority");
		dto.setSource("mock service");
		list.add(dto);
		
		for(int i = from + 2; i < Math.min(to, getReceivedEventsCount()); i++) {
			dto = new EventDTO();
			dto.setId(Long.valueOf(i));
			dto.setEventDate(new Date());
			dto.setPriority("Normal");
			dto.setSource("mock service");
			list.add(dto);
		}
		
		return list;
	}

	@Override
	public long getReceivedEventsCount() {
		Logger.getLogger(this.getClass()).info("getReceivedEventsCount()");
		return 112;
	}

}
